<?php
/**
 * Created by PhpStorm.
 * User: ZhangWei
 * Date: 2018/4/12
 * Time: 17:08
 */

namespace App\Http\Controllers\Api\V1;


use App\Http\Resources\Material as MaterialResources;
use App\Logic\MaterialLogic;
use Illuminate\Http\Request;

class PublicController extends BaseController
{
    public function getWxSing()
    {
        $data = $this->getJsSdkConfig();

        return $this->success($data);
    }


    public function uploadImage(Request $request)
    {
        $user = $this->getUser();
        $mode = $request->input("mode", 'doc');
        list($state, $obj) = MaterialLogic::upLoadImage($request, $user, $mode);
        if ($state) {
            $material = new MaterialResources($obj);
            return $this->success($material);
        } else {
            return $this->failed($obj);
        }
    }

    public function articleContentUploadImage(Request $request)
    {
        //return $this->failed('xxx');
        $user = $this->getUser();
        $mode = 'article';
        list($state, $obj) = MaterialLogic::upLoadImage($request, $user, $mode, false);
        if ($state) {
            return $this->success($obj);
        } else {
            return $this->failed($obj);
        }
    }

    public function articleContentUploadVideo(Request $request)
    {
        //return $this->failed('xxx');
        $user = $this->getUser();
        $mode = 'article';
        list($state, $obj) = MaterialLogic::uploadVideo($request, $user, $mode, false);
        if ($state) {
            return $this->success($obj);
        } else {
            return $this->failed($obj);
        }
    }
}